/**
 * Created by sa on 16-9-9.
 */
$(function () {
	//下载页
	$("#install").on("click",function(){
		var u = navigator.userAgent;
		var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端
		if(isAndroid){
			window.location.href="https://play.google.com/store/apps/details?id=com.superheadlines.android";
		}else{
			window.location.href="https://itunes.apple.com/us/app/chao-ji-tou-tiao/id1149308012?l=zh&ls=1&mt=8";
		}
	});
    function GetQueryString(name)
    {
        var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if(r!=null)return  unescape(r[2]); return null;
    }
    video_info();
    //视频详情接口
    function video_info(a,b) {
        var video_id = a?a:GetQueryString("video_id");
        video_id = "58391e2b212d6b162b608a16";
        $.ajax({
            type:"GET",
            url:"http://api.headlines.video/api/video/info?video_id="+video_id+"&device_id=1",
            success:function (res) {
                var data= JSON.parse(res);
                var html = template("video_detail",data.data);
                $("#video").append(html);
                $("#video .video_play_content h5 img").on("click",function(){
                	 $("#install").click();
                });
                video_list(a,b);
            },
        });
    }
    //视频列表接口
    function video_list(a,b) {
        var video_id = a?a:GetQueryString("video_id");
        video_id = "58391e2b212d6b162b608a16";
        $.ajax({
            type:"GET",
            url:"http://api.headlines.video/api/recommend/vidoe/reated?video_id="+video_id+"&device_id=1",
            success:function (res) {
                var data= JSON.parse(res);
                var html = template("video_list",data);
                $(".video_list").append(html);
                $("#video .video_list ul li:nth-child("+data.data.length+")").css("margin-bottom","44px");
                $(".video_list ul li").on("click",function () {
                   $("#install").click();
                });   
            },
        });
    }

});